home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Our Solar System
/
Our Solar System.iso
/
miscprog
/
targ
/
timer.c
< prev
Wrap
Text File
|
1987-03-23
|
2KB
|
88 lines
/* timer.c -- Contains wait(), which is a timed wait loop.
Caller specifies the time he wants to wait, in
tenths of a second. IBM PC ROM-BIOS dependent!
History: rhs 15-mar-87 ... Original
rhs 18-mar-87 ... Added wait_keytime(), which is based on wait().
(For use with Targ-Hurt ESP Trainer.)
*/
#include <math.h>
#include <dos.h>
#include <conio.h>
#include "mancon.h"
#include "declares.h"
long readclock();
void wait(int);
/* wait -- loops for "tenths" tenths of a second, then returns.
*/
void wait(tenths)
int tenths;
{ long clocks, end, recent, remaining;
int newday=FALSE;
clocks=(long)((float)tenths*1.821);
end=readclock(&newday)+clocks;
while( (recent=readclock(&newday)) < end )
if(newday) end=remaining; /* newday=TRUE is returned only */
else remaining=end-recent; /* once every 24 hours, at midnight */
}
/* wait_keytime -- loops for "tenths" tenths of a second, or until a key is
pressed.
*/
void wait_keytime(tenths)
int tenths;
{ long clocks, end, recent, remaining;
int newday=FALSE;
clocks=(long)((float)tenths*1.821);
end=readclock(&newday)+clocks;
while( (recent=readclock(&newday)) < end && kbhit()==0 )
if(newday) end=remaining; /* newday=TRUE is returned only */
else remaining=end-recent; /* once every 24 hours, at midnight */
}
static union REGS regs;
/* readclock -- Use interrupt 26 to read the current system time.
The time is returned in clocks (18.21 clocks per second.)
*/
long readclock(newday)
int *newday;
{ *newday=FALSE;
regs.h.ah=0;
int86(26,®s, ®s);
if(regs.h.al != 0) *newday=TRUE;
return( ((long)regs.x.cx<<16)+(long)regs.x.dx);
}
/* Test main */
/*
main(argc, argv)
int argc;
char *argv[];
{ int pause=atoi(argv[1]);
char time[15];
printf("beginning\n");
systime(time,11);
printf("%s\n", time);
wait(pause);
systime(time,11);
printf("%s\n", time);
printf("done");
}
*/